package org.yinweichen.llm_dataset_backend.repository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.yinweichen.llm_dataset_backend.entity.CandidateAnswer;
import org.yinweichen.llm_dataset_backend.entity.CandidateAnswerId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CandidateAnswerRepository extends JpaRepository<CandidateAnswer, CandidateAnswerId> {
    List<CandidateAnswer> findByStandardQuestionIdAndStandardQuestionVersion(Long questionId, String version);

    @Modifying
    @Query("UPDATE CandidateAnswer a SET a.answer = :answer, a.updateTime = CURRENT_TIMESTAMP WHERE a.id = :id AND a.version = :version")
    int update(@Param("id") Long id, @Param("version") String version, @Param("answer") String answer);

    boolean existsById(Long id);
}
